<template>
  <div class="body">
    <!-- 头部 -->

    <div class="header">
      <van-icon @click="todolist" name="arrow-left" />
    </div>

    <!-- 内容 -->
    <div class="main">
      <div class="nav">
        <span>我的金币</span>
        <i>
          <img src="./../assets/image/invite2.png" alt="" />
          {{ money }}
        </i>
      </div>
      <!-- 格子 -->
      <ul class="GongGe">
        <li v-for="item in list" :key="item.id">
          <p><img :src="item.src" alt="" /></p>
          <div class="text-G">
            <p>
              <em>{{ item.title }}</em>
            </p>
            <p>
              <span>已售{{ item.sellNum }}</span>
              <em>
                <img src="./../assets/image/invite2.png" alt="" />
                {{ item.price }}
              </em>
            </p>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { ref, onMounted } from "vue";
import { inviteApi, getMyInfoApi } from "../utils/api";
export default {
  setup() {
    const list = ref([]);
    const cout = ref(5);
    const token = localStorage.getItem("token");
    const money = ref();
    onMounted(async () => {
      const res = await inviteApi();
      ///console.log(res);
      if (res.status === 0) {
        list.value = res.classList;
        //console.log(list.value)
      }
      const res1 = await getMyInfoApi({ token });
      money.value = res1.results.myMoney;
      // console.log(res1);
      console.log(money);
      // console.log("Component is mounted!");
    });

    return { cout, list, money };
  },
  methods: {
    todolist() {
      this.$router.go(-1);
    },
  },
};
</script>

<style lang="less" scoped>
.header {
  width: 100%;
  height: 300px;
  background-image: url(./../assets/image/invite1.png);
  background-size: 100%;
  position: relative;
  > .van-icon {
    position: absolute;
    top: 17px;
    left: 5px;
    font-size: 18px;
    font-weight: 900;
    color: rgb(35, 21, 228);
  }
}
.main {
  width: 95%;
  margin: auto;
  //background: rgb(51, 156, 255);
  .GongGe {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    li {
      margin-bottom: 20px;
      box-shadow: 0 0 8px 1px rgb(211, 211, 211);
      width: 48%;
      background: #e6e6e6;
      p > img {
        width: 100%;
      }
      .text-G {
        height: 70px;
        //background: blue;
        display: flex;
        flex-direction: column;
        padding: 10px;
        justify-content: space-between;
      }
      p {
        display: flex;
        justify-content: space-between;
        font-size: 15px;
        em {
          font-weight: 800;
          img {
            width: 14px;
          }
        }
      }
    }
  }
}
.nav {
  height: 60px;
  display: flex;
  font-size: 16px;
  line-height: 70px;
  img {
    width: 14px;
  }
  span,
  i {
    font-weight: 700;
  }
  i {
    padding-left: 20px;
    flex: 3;
  }
}
</style>
